package com.yj.spider.listener;

import com.google.common.util.concurrent.Service;

/**
 * YjSpider爬虫服务listener,在爬虫状态转换时调用对应的方法，执行任务
 */
public class YjSpiderListener extends  Service.Listener {

    /**
     * Called when the service transitions from {@linkplain Service.State#NEW NEW} to
     * {@linkplain Service.State#STARTING STARTING}. This occurs when {@link Service#startAsync} is called
     * the first time.
     */
    public void starting() {}

    /**
     * Called when the service transitions from {@linkplain Service.State#STARTING STARTING} to
     * {@linkplain Service.State#RUNNING RUNNING}. This occurs when a service has successfully started.
     */
    public void running() {}

    /**
     * Called when the service transitions to the {@linkplain Service.State#STOPPING STOPPING} state. The
     * only valid values for {@code from} are {@linkplain Service.State#STARTING STARTING} or
     * {@linkplain Service.State#RUNNING RUNNING}. This occurs when {@link Service#stopAsync} is called.
     *
     * @param from The previous state that is being transitioned from.
     */
    public void stopping(Service.State from) {}

    /**
     * Called when the service transitions to the {@linkplain Service.State#TERMINATED TERMINATED} state.
     * The {@linkplain Service.State#TERMINATED TERMINATED} state is a terminal state in the transition
     * diagram. Therefore, if this method is called, no other methods will be called on the
     * {@link Service.Listener}.
     *
     * @param from The previous state that is being transitioned from. The only valid values for
     *     this are {@linkplain Service.State#NEW NEW}, {@linkplain Service.State#RUNNING RUNNING} or
     *     {@linkplain Service.State#STOPPING STOPPING}.
     */
    public void terminated(Service.State from) {}

    /**
     * Called when the service transitions to the {@linkplain Service.State#FAILED FAILED} state. The
     * {@linkplain Service.State#FAILED FAILED} state is a terminal state in the transition diagram.
     * Therefore, if this method is called, no other methods will be called on the {@link Service.Listener}.
     *
     * @param from The previous state that is being transitioned from. Failure can occur in any
     *     state with the exception of {@linkplain Service.State#NEW NEW} or {@linkplain Service.State#TERMINATED
     *     TERMINATED}.
     * @param failure The exception that caused the failure.
     */
    public void failed(Service.State from, Throwable failure) {}

}
